'''
二分法查找
'''

import math


def binary_search(list, item):
    low = 0
    high = len(list) - 1

    while low <= high:
        mid = math.ceil((low + high)/2)
        # mid = (low + high)
        guess = list[mid]

        if guess == item :
            return mid
        elif guess > item :
            high = mid - 1
        elif guess < item :
            low = mid + 1

    return None

my_list = []
for i in range(999999):
    my_list.append(i)

print(binary_search(my_list, 3))
# print(binary_search(my_list, 7))
# print(binary_search(my_list, 0))